import os
from datetime import datetime


def write_repair_log(action,  username,device_id=None, record_id=None, message=""):
    

   
    log_dir = os.path.join(os.path.dirname(__file__), '..', '..', 'log')
    os.makedirs(log_dir, exist_ok=True)
    log_path = os.path.join(log_dir, 'repair.log')
    now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    log_line = f"[{now}] 操作: {action} 用户: {username} 设备ID: {device_id} 维修单ID: {record_id} 详情: {message}\n"
    with open(log_path, 'a', encoding='utf-8') as f:
        f.write(log_line)